var database = require('../../data/data.js');
var app = getApp()
Page({
  data: {
    bean1: {},
    bean2: {},
    bean3: {}
  },
  step1: function () {
    var that = this
    wx.login({
      success: function (res) {
        if (res.code) {
          //发起网络请求
          wx.request({
            url: database.url + '/project/step1.action',
            data: {
              code: res.code
            },
            success: function (res) {
              var pages = getCurrentPages();
              var page = pages[pages.length - 1];
              page.setData({ bean1: res.data });
              console.log(that.data.bean1)
            }
          })
          
        } else {
          console.log('获取用户登录态失败！' + res.errMsg)
        }
      }
    });
  },
  step2: function () {
    var that = this
    wx.request({
      url: database.url + '/project/step2.action?body=' + 'LawyerWang' + '&total_fee=' + 1000,
      data: {
        openid: this.data.bean1.openid
      },
      success: function (res) {
        var pages = getCurrentPages();
        var page = pages[pages.length - 1];
        page.setData({ bean2: res.data });
        console.log(that.data.bean2)
      }
    })
  },
  step3: function () {
    var that = this
    wx.request({
      url: database.url + '/project/step3.action',
      data: {
        prepay_id: this.data.bean2.prepay_id,
        
      },
      success: function (res) {
        var pages = getCurrentPages();
        var page = pages[pages.length - 1];
        page.setData({ bean3: res.data });
        console.log(that.data.bean3)
      }
    })
  },
  step4: function () {
    wx.requestPayment(
      {
        'timeStamp': this.data.bean3.timeStamp,
        'nonceStr': this.data.bean3.nonceStr,
        'package': 'prepay_id=' + this.data.bean2.prepay_id,
        'signType': 'MD5',
        'paySign': this.data.bean3.paySign,
        'success': function (res) {
          console.log("支付成功！")
          console.log(res);
          that.subAOrder();
        },
        'fail': function (res) {
          console.log(res);
        }
      })
  }
})
